import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sainbainu/common/values/colors.dart';
import 'package:sainbainu/common/widgets/widget.dart';

import 'index.dart';

class PasswordChangePage extends GetView<PasswordChangeController> {
  const PasswordChangePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PasswordChangeController>(
      builder: (_) {
        return KeyboardClose(
          child: Scaffold(
            appBar: AppBar(title: Text("密码设置".tr)),
            body: _buildWrapper([
              _buildInput(
                labelText: '输入新密码'.tr,
                controller: _.state.passwdController,
              ),
              const SizedBox(height: 15),
              _buildInput(
                labelText: '再次输入新密码'.tr,
                controller: _.state.passwdCheckController,
              ),
              const SizedBox(height: 30),
              SizedBox(
                width: double.infinity,
                height: 50,
                child: ElevatedButton(
                  style: ElevatedButton.styleFrom(
                    backgroundColor: AppColors.danger,
                    foregroundColor: Colors.white,
                  ),
                  onPressed: () => _.handleSubmit(),
                  child: Text('确认设置'.tr),
                ),
              ),
            ]),
          ),
        );
      },
    );
  }

  Widget _buildWrapper(List<Widget> children) {
    return SingleChildScrollView(
      physics: const BouncingScrollPhysics(),
      child: Padding(
        padding: const EdgeInsets.all(15),
        child: Container(
          padding: const EdgeInsets.all(15),
          decoration: const BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(10)),
          ),
          child: Column(
            children: children,
          ),
        ),
      ),
    );
  }

  Widget _buildInput({
    required String labelText,
    TextEditingController? controller,
    bool obscureText = true,
  }) {
    return Container(
      decoration: const BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(10)),
      ),
      clipBehavior: Clip.antiAlias,
      child: TextField(
        controller: controller,
        decoration: InputDecoration(
          border: InputBorder.none,
          fillColor: AppColors.page,
          filled: true,
          isDense: true,
          labelText: labelText,
          labelStyle: const TextStyle(color: AppColors.active),
          floatingLabelStyle: const TextStyle(color: AppColors.success),
        ),
        keyboardType: TextInputType.text,
        textInputAction: TextInputAction.go,
        cursorColor: AppColors.active,
        cursorErrorColor: AppColors.active,
        cursorHeight: 16,
        obscureText: obscureText,
      ),
    );
  }
}
